<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="org.apache.catalina.Session"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="cn.ticket.db.DBConnect"%>
<%@ page import="cn.ticket.Constant"%>
<%@ page import="cn.ticket.util.StringUtil"%>
<%@ page import="cn.ticket.util.CommonEncryption"%>
<% 
	String email=request.getParameter("email") ;
	String  name=request.getParameter("name") ;
	String password = request.getParameter("password") ;
	String re_password= request.getParameter("re_password") ;
	String user_type = request.getParameter("type") ;
	
	int type = null!=user_type && !"".equals(user_type)?Integer.parseInt(user_type):0 ;
	if(null==email || "".equals(email)){
		session.setAttribute("errorinfo", Constant.ERRORINFO_NETERROR) ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}
	if(null==name || "".equals(name)){
		session.setAttribute("errorinfo", Constant.ERRORINFO_NETERROR) ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}
	if(null==password || "".equals(password) ||null==re_password || "".equals(re_password)){
		session.setAttribute("errorinfo", Constant.ERRORINFO_NETERROR) ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}else if(!password.equals(re_password)){
		session.setAttribute("errorinfo", "两密码不一致.请确定后再提交.") ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}else
	String id = StringUtil.createUUID() ;
	Connection con = new DBConnect().DBConnection() ;
	try {
		PreparedStatement pstmt =  con.prepareStatement("insert into user(id,name,password,email,type,creTime,status) values(?,?,?,?,?,?,?)") ;
		pstmt.setString(1,id) ;
		pstmt.setString(2,name) ;
		pstmt.setString(3,password) ;
		pstmt.setString(4,email) ;
		pstmt.setInt(5,type) ;
		pstmt.setDate(6, new java.sql.Date(new java.util.Date().getTime())) ;
		pstmt.setInt(7, 0) ;
		pstmt.execute();
		session.removeAttribute("login_user_name") ;
		session.setAttribute("login_user_name", name) ;
		session.removeAttribute("login_user_type") ;				
		session.setAttribute("login_user_type", type) ;
		session.removeAttribute("login_user_id") ;				
		session.setAttribute("login_user_id", id ) ;
		if(type==Constant.USER_COMUSER){
			%>
			<jsp:forward page="home_comUser.jsp" />
			<%
		}else if(type==Constant.USER_PARTNER){
			%>
			<jsp:forward page="home_partner.jsp" />
			<%
		}else if(type==Constant.USER_ADMIN){
			%>
			<jsp:forward page="home_admin.jsp" />
			<%
		}
	}catch(Exception e){
		out.print("发生异常了."+e.getMessage()) ;
		%>
		<jsp:forward page="result.jsp" />
		<%
	}
%>